Modern computer systems require a large amount of random access memory (RAM) to run software programs. Processes that each execute software, such as the operating system and various application programs, constantly interact with data stored in RAM. Each process is assigned “pages” of RAM to use. The pages are units of memory whose size depends on the host computer system.
As computers became more sophisticated and complex, processes required more memory than is physically available in RAM. Virtual addresses for memory overcome this problem by allowing processes to share physical RAM. Such sharing is achieved by extending the memory address space to create a virtual address space. Virtual addresses allow the memory to appear as though there is a large amount of memory.
This memory is regarded as “virtual” memory because, at any given time, some of the pages allocated to processes do not exist in RAM. Rather, a memory manager performs what are called paging operations in which the contents of some pages are stored in slower, non-volatile memory when not actively in use and are brought into the faster RAM when they are to be accessed.
The memory manager operates to provide pages associated with a virtual address in physical RAM when those pages are needed. The set of pages in the virtual address space that currently reside in RAM is known as the “working set.” When contents of a particular virtual page is needed, but that page is not stored in the RAM, the memory manager may retrieve that data from non-volatile memory and make it available in the RAM. Conversely, when a process requires more memory than is free in the RAM, the memory manager may “trim” pages from the working set by removing the contents of one or more pages in RAM and ensuring that the contents is stored in the non-volatile storage. Trimming pages frees up space in the RAM for other pages to be brought into RAM.
To perform paging operations, page tables are used to store a mapping between virtual and physical addresses. In addition to the mapping, page table entries (PTEs) often include a page offset, and information which details use of the page. This information may be in the form of an access bit, which indicates whether the page has been accessed during an interval since the access bit was reset. In addition to an access bit, an age count provides information that details the use of the page. The age count is often stored in a working set list entry (WSLE), and indicates the number of successive intervals during which the page was not accessed. This information is used by the memory manager to determine which pages to trim when the amount of available RAM becomes so limited that the most frequently accessed pages are kept in RAM and the less frequently accessed pages are paged out to make more RAM available. The age count is set by the memory manager through an operation called “aging.” Aging tracks access history of pages in a working set by periodically checking whether each page has been accessed during an interval since access to the page was last checked. Such a check may be performed by periodically checking whether the access bit for the page is set. If so, the page has been accessed and the age count for the page is reset. The access bit is also reset. If not, the age count for the page may be increased, up to some maximum count established by the number of bits in the WSLE (or PTE) allocated for holding the age count. The age count allows the memory manager to select pages that can be trimmed with low likelihood that performance of the computer system will be impacted by removing from the working set a page that is actively being used.
Because aging information is used when pages need to be trimmed from the working set, a computer system may perform aging only when the working set occupies more than some threshold amount of the RAM, thus avoiding the CPU and memory costs of conducting an aging scan.